package other.xsy.passlys.receivable;

import com.alibaba.fastjson.JSONObject;
import com.rkhd.platform.sdk.data.model.Debooking__c;
import com.rkhd.platform.sdk.exception.ScriptBusinessException;
import com.rkhd.platform.sdk.log.Logger;
import com.rkhd.platform.sdk.log.LoggerFactory;
import com.rkhd.platform.sdk.model.XObject;
import com.rkhd.platform.sdk.trigger.DataResult;
import com.rkhd.platform.sdk.trigger.Trigger;
import com.rkhd.platform.sdk.trigger.TriggerRequest;
import com.rkhd.platform.sdk.trigger.TriggerResponse;
import other.xsy.passlys.util.HCXObjectService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description 删除deBooking
 * @Author 黎炎松
 * 2024-08-14 17:02
 */
public class DeBookingDel implements Trigger {

    private static HCXObjectService hcxObjectService = new HCXObjectService();
    private static final Logger logger = LoggerFactory.getLogger();


    public static void main(String[] args) throws Exception {
        DeBookingDel deBoookingDel = new DeBookingDel();

        TriggerRequest request = new TriggerRequest();
        Debooking__c debooking = new Debooking__c();
        debooking.setId(3424376008874601L);
        debooking = hcxObjectService.get(debooking);
        debooking.setBookingStr__c("3422058447968910,3422058331478678");
        request.setDataList(Arrays.asList(debooking));

        deBoookingDel.execute(request);
    }

    @Override
    public TriggerResponse execute(TriggerRequest request) throws ScriptBusinessException {
        logger.debug("删除deBooking ");
        List<XObject> dataList = request.getDataList();
        List<DataResult> dataResultList = new ArrayList<>();
        List<XObject> objectList = new ArrayList<>();
        for (XObject xObject : dataList) {
            objectList.add(xObject);

            dataResultList.add(new DataResult(true, "", xObject));
        }

        // 触发修改相关字段
        Debooking__c debooking = (Debooking__c) objectList.get(0);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sceneType", 2);
        jsonObject.put("deBookingId", debooking.getId());
        jsonObject.put("YNrefund", debooking.getYNrefund__c());
        jsonObject.put("runningWater", debooking.getRunningWater__c());
        jsonObject.put("bookingStr", debooking.getBookingStr__c());
        logger.debug("删除deBooking jsonObject " + jsonObject);
        ReceivableService receivableService = new ReceivableService();
        receivableService.calcDeBookingAmount(jsonObject);



        return new TriggerResponse(true, "处理完成", dataResultList);
    }

}
